382e0c609b4e16eae0201dfe2f7ca15a5f8c17e3,opennms-services/src/main/java/org/opennms/netmgt/config/EventconfFactory.java,EventconfFactory,reload,#,152

Before Change


     * 
     */
    public static synchronized void reload() throws IOException, MarshalException, ValidationException {
        InputStream configIn = new FileInputStream(m_rootConfigFile);
        Events events = ((Events) Unmarshaller.unmarshal(Events.class, new InputStreamReader(configIn)));
       
        m_eventFiles=new HashMap<File, Events>();
        m_eventFiles.put(m_rootConfigFile, events);

        //Create an array, and add any nested eventfiles defs found, to the end of the array.  
        //Using the "size" field (rather than an enumeration) means we don't need any funky nesting logic
        List<String> eventFiles=new ArrayList(events.getEventFileCollection());
        
        for(int i=0; i<eventFiles.size(); i++) {
            String eventFilePath = (String) eventFiles.get(i);
            File eventFile=new File(eventFilePath);
            if(!eventFile.isAbsolute()) {
                //This event file is specified with a relative path.  Get the absolute path relative to the root config file, and use 
                // that for all later file references
                File tempFile=new File(m_rootConfigFile.getParent() + File.separator + eventFile.getPath());
                eventFile=tempFile.getCanonicalFile();
            }
            InputStream fileIn = new FileInputStream(eventFile);
            if (fileIn == null) {
                throw new IOException("Eventconf: Failed to load/locate events file: " + eventFile);
            }

            Reader filerdr = new InputStreamReader(fileIn);
            Events filelevel = null;
            filelevel = (Events) Unmarshaller.unmarshal(Events.class, filerdr);
            m_eventFiles.put(eventFile, filelevel);
            
            //There are nested event-file definitions - load them as well
            if(filelevel.getEventFileCount()>0) {
                eventFiles.addAll(filelevel.getEventFileCollection());
            }
        }

After Change


     * 
     */
    public static synchronized void reload() throws IOException, MarshalException, ValidationException {
        Events events = CastorUtils.unmarshal(Events.class, new FileReader(m_rootConfigFile));
       
        m_eventFiles = new HashMap<File, Events>();
        m_eventFiles.put(m_rootConfigFile, events);

        /*
         * Create an array, and add any nested eventfiles defs found, to the end of the array.  
         * Using the "size" field (rather than an enumeration) means we don't need any funky nesting logic
         */
        List<String> eventFiles = new ArrayList<String>(events.getEventFileCollection());
        
        for (String eventFilePath : eventFiles) {
            File eventFile = new File(eventFilePath);
            if (!eventFile.isAbsolute()) {
                /*
                 * This event file is specified with a relative path.  Get the absolute path relative to the root config file, and use 
                 * that for all later file references
                 */
                File tempFile = new File(m_rootConfigFile.getParent() + File.separator + eventFile.getPath());
                eventFile = tempFile.getCanonicalFile();
            }
            
            FileReader fileIn = new FileReader(eventFile);
            if (fileIn == null) {
                throw new IOException("Eventconf: Failed to load/locate events file: " + eventFile);
            }

            Events filelevel = CastorUtils.unmarshal(Events.class, fileIn);
            m_eventFiles.put(eventFile, filelevel);
            
            if (filelevel.getGlobal() != null) {
                throw new ValidationException("The event file " + eventFile + " included from the top-level event configuration file cannot have a 'global' element");
            }
            if (filelevel.getEventFileCollection().size() > 0) {
                throw new ValidationException("The event file " + eventFile + " included from the top-level event configuration file cannot include other configuration files: " + StringUtils.collectionToCommaDelimitedString(filelevel.getEventFileCollection()));
            }
        }